package com.hc.sort.server.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.hc.sort.server.pojo.Admin;
import com.hc.sort.utils.JdbcUtil;

public class AdminDaoImpl implements AdminDao {
	PreparedStatement  pstmt = null;
	Connection conn = null;
	ResultSet rs = null;
	
	@Override
	public Admin LoginAdmin(String userName, String password) {
		String sql="select * from t_admin where adm_username=? and  adm_password=?";
		
		try {
			conn=JdbcUtil.getConnection();
			pstmt=conn.prepareStatement(sql);
			
			pstmt.setObject(1, userName);
			pstmt.setObject(2, password);
			
			rs=pstmt.executeQuery();
			while(rs.next()) {
				Admin admin=new Admin();
				admin.setId(rs.getInt("ADM_ID"));
				admin.setUserName(rs.getString("ADM_USERNAME"));
				admin.setPassword(rs.getString("ADM_PASSWORD"));
				
				return admin;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally {
			JdbcUtil.close(rs,pstmt,conn);
		}
		return null;
	}
	
	public static void main(String[] args) {
		AdminDao adminDao=new AdminDaoImpl();
		System.out.println(adminDao.LoginAdmin("tom", "123456"));
	}
}
